package com.app.news.util;

import android.content.ContentValues;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

import androidx.annotation.Nullable;

public class MyHelper extends SQLiteOpenHelper {
    public MyHelper(@Nullable Context context) {
        super(context, "hannianfeng", null, 1);
    }

    @Override
    public void onCreate(SQLiteDatabase db) {
        db.execSQL("create table account(id integer primary key autoincrement," +
                "username varchar(20) not null,pwd varchar(20) not null)");
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {

    }
    public void insert(Context context,String username,String pwd){
        MyHelper myHelper=new MyHelper(context);
        SQLiteDatabase db1=myHelper.getWritableDatabase();
        ContentValues values=new ContentValues();
        values.put("username",username);
        values.put("pwd",pwd);
        long id=db1.insert("account",null,values);
        db1.close();
    }
}
